/**
 * 观察者
 */
export default class Observe {
    constructor() {
        this.subscribers = {};
    }
 
    bind(event, subscriber) {
        if (!this.subscribers[event]) {
            this.subscribers[event] = [];
        }
        this.subscribers[event].push(subscriber);
    }
 
    unbind(event, subscriber) {
        if (this.subscribers[event]) {
            this.subscribers[event] = this.subscribers[event].filter(sub => sub !== subscriber);
        }
    }
 
    emit(event, message) {
        if (this.subscribers[event]) {
            this.subscribers[event].forEach(subscriber => {
                subscriber.update(message);
            });
        }
    }
}